package br.com.jbssistemas.loterica.sevice;

import br.com.jbssistemas.loterica.hibernate.HibernateUtil;
import br.com.jbssistemas.loterica.util.ReportUtil;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperRunManager;

/**
 *
 * @author daniel
 * 
 */

public class RelatorioService {

    public void imprimirRelatorio(String diretorio, String relatorio, Date dataInicial, Date dataFinal) 
            throws ParseException, JRException, IOException, SQLException {

        ReportUtil reportUtil = new ReportUtil();

        HashMap parametros = new HashMap();
        
        parametros.put("DATA_INICIAL", dataInicial);
        
        parametros.put("DATA_FINAL", dataFinal);
        
        parametros.put("SUBREPORT_DIR", reportUtil.getJavaPath() + "/" + diretorio + "/");

        Connection connection = HibernateUtil.getConnection();
        
        byte[] pdfRelatorio = JasperRunManager.runReportToPdf(reportUtil.getJavaPath() + "/" + diretorio + "/"+relatorio+".jasper", parametros, connection);

        reportUtil.mostrarRelatorio(pdfRelatorio, reportUtil.getResponse(), relatorio);

    }
    
}
